<%@ page import="java.net.URLDecoder" %><%--
  Created by IntelliJ IDEA.
  User: success
  Date: 2019/9/12 0012
  Time: 9:18
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang='en'>
<head>
    <meta charset='UTF-8'>
    <meta name='viewport' content='width=device-width, initial-scale=1.0'>
    <meta http-equiv='X-UA-Compatible' content='ie=edge'>
    <title>手机商城</title>
    <!-- 引入bootstrap框架的样式文件 -->
    <link rel='stylesheet' href='${path}/plugins/bootstrap/css/bootstrap.css' type='text/css'>
    <link rel='stylesheet' href='${path}/css/nav.css' type='text/css'>
</head>
<body>
    <%--第一种解决方案 - 利用jsp的代码块来处理--%>
    <%
        //获取cookie
        //每次请求的时候,会将所有的cookie全部发送给server
        Cookie[] cookies = request.getCookies();

        String uname="";
        String pwd="";
        //定义一个标记位
        boolean flag = false;

        if(null!=cookies && cookies.length>0){
            for(Cookie c:cookies){
                //找到name=username的cookie
                if("userLogin".equals(c.getName())){
                    String value = c.getValue();

                    if(value.trim().length()==0){
                        break;
                    }
                    // System.out.println(value.split(":")[0]);

                    //如果对用户名进行二级编码,那么此处需要进行二级解码
                    uname = value.split(":")[0];

                    uname = URLDecoder.decode(URLDecoder.decode(uname,"utf-8"),"utf-8");

                    pwd = value.split(":")[1];

                    flag = true;
                    break;
                }
            }
        }

        pageContext.setAttribute("uname",uname);
        pageContext.setAttribute("pwd",pwd);
        pageContext.setAttribute("flag",flag);


    %>

    <!--引入导航 - 静态包含引入路径的时候千万不要出现EL-->
    <%--<%@ include file="../common/nav.jsp"%>--%>

    <!--login-->
    <div class='container'>
        <div class='row'>
            <div class='modal-dialog'>
                <div class='modal-content'>
                    <div class='modal-header'>
                        <button type='button' class='close' data-dismiss='modal' aria-hidden='true'>&times</button>
                        <h4 class='modal-title' id='myModalLabel'>用户Load入口</h4>
                    </div>
                    <div class='modal-body'>
                        <form action='<%=request.getContextPath()%>/user/loadList' method='post' class='form-horizontal' role='form'>
                            <div class='form-group has-feedback'>
                                <label for='firstname' class='col-sm-2 control-label'>用户名</label>
                                <div class='col-md-6'>
                                    <input type='text' value='${uname}' name='username' class='form-control' id='firstname' placeholder='请输入用户名'>
                                    <span class='glyphicon glyphicon-user form-control-feedback'></span>
                                </div>

                                <c:if test="${param.error==0}">
                                    <div class='col-md-3' style='padding-top:3px'>
                                        <span class='text-danger'>用户不存在!</span>
                                    </div>
                                </c:if>

                            </div>
                            <div class='form-group has-feedback'>
                                <label for='lastname' class='col-sm-2 control-label'>密码</label>
                                <div class='col-md-6'>
                                    <input type='password' value='${pwd}' name='password' class='form-control' id='lastname' placeholder='请输入密码'>
                                    <span class='form-control-feedback glyphicon glyphicon-lock'></span>
                                </div>

                                <c:if test="${param.error==1}">
                                    <div class='col-md-3' style='padding-top:3px'>
                                        <span class='text-danger'>密码错误!</span>
                                    </div>
                                </c:if>

                            </div>
                            <div class='form-group'>
                                <div class='col-sm-offset-2 col-sm-10'>
                                    <div class='checkbox'>
                                        <label>
                                            <c:if test="${flag}">
                                                <input type='checkbox' name='flag' checked>请记住我</label>
                                            </c:if>
                                        <c:if test="${!flag}">
                                            <input type='checkbox' name='flag'>请记住我</label>
                                        </c:if>

                                    </div>
                                </div>
                            </div>
                            <div class='form-group'>
                                <div class='col-sm-offset-2 col-sm-10'>
                                    <button type='submit' class='btn btn-default'>登录</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script src='${path}/plugins/jquery/jquery.min.js'></script>
    <script src='${path}/plugins/bootstrap/js/bootstrap.js'></script>
</body>
